import type { PluginOption, ViteDevServer } from 'vite';
import colors from 'picocolors';//控制台顔色插件

export default function vitePluginVueMonitor(): PluginOption {

    return {
        name: 'ts-start',
        apply: 'serve',
        enforce: 'pre',
        configureServer(server: ViteDevServer) {
            const print = server.printUrls;
            server.printUrls = () => {
                const network = server.resolvedUrls?.network[0];
                const local = server.resolvedUrls?.local[0];
                if (!network && !local) {
                    console.log(colors.red('获取IP地址失败,请检查vite.config.ts文件中server.host配置是否正确!\n'))
                } else {
                    console.info(colors.green("Hello World"))
                    print();
                }
            }
        }
    }
}
